---@class UIBattleReady : UIBase
UIBattleReady = UIBase.New(PanelNames.UIBattleReady)

function UIBattleReady:Init(HeroIdList)
    self.HeroIdList = HeroIdList
end
function UIBattleReady:OnCreate()
    self.btnStart = self:GetChild("btnStart")
    self:RegisterOnClick(self.btnStart,self.ClickStart)
    ---@type HeroBigIcon[]
    self.itemList = {}
    for i = 0,7 do
        local item = self:GetChild("hero"..i)
        table.insert(self.itemList,item)
    end
    self:Refresh()
end
function UIBattleReady:OnDestroy()

end
function UIBattleReady:Refresh()
    for k,v in pairs(self.itemList) do
        local heroId = self.HeroIdList[k]
        if heroId then
            v:SetHeroId(heroId)
        else
            v:SetEmpty()
        end
    end
end
function UIBattleReady:ClickStart()
    closeUI(PanelNames.UIBattleReady)
    closeUI(PanelNames.UIMainPage)
    local cardList = {}
    for k,v in pairs(self.HeroIdList) do
        table.insert(cardList,Battle.Card.New():Set(v,1))
    end
    local bat = Battle.CBattle.CreateBattle()
    bat:SetCardList(bat:CreateCardsByIdList(self.HeroIdList),bat:CreateCardsByIdList(decodeJsonStrToTable(Battle.GlobalConfig.GetString(21))))
    bat:LoadAndFight()
end
return UIBattleReady